package com.example.liujie.actor

import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion

class ActorGame : ApplicationAdapter() {
    lateinit var batch: SpriteBatch
    lateinit var texture: Texture
    lateinit var myActor: MyActor

    override fun create() {
        super.create()
        batch = SpriteBatch()
        texture = Texture(Gdx.files.internal("a.jpg"))
        myActor = MyActor(TextureRegion(texture))
        myActor.setPosition(0f, 100F)
        myActor.setOrigin(0f, 0f)
        myActor.setScale(0.5F, 1.0F)
        // 顺时针旋转 5 度
        myActor.setRotation(-5f)

    }

    override fun render() {
        super.render()
        // 黑色清屏
        Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
        // 更新演员逻辑
        myActor.act(Gdx.graphics.getDeltaTime())

        batch.begin()

        // 绘制演员（这里暂且先直接绘制, 位置相对于屏幕左下角）
        myActor.draw(batch, 1.0F)

        batch.end()
    }

    override fun dispose() {
        super.dispose()
        batch?.dispose()
        texture?.dispose()

    }
}